import 'package:flutter_elf/config/component_index.dart';
import 'package:flutter_elf/widgets/appbar_creator.dart';

class OverlayPage extends BaseWidget{
  @override
  BaseWidgetState<BaseWidget> getState() {
    // TODO: implement getState
    return OverlayPageState();
  }
}

class OverlayPageState extends BaseWidgetState<OverlayPage>{

  @override
  void onCreate() {
    // TODO: implement onCreate
    super.onCreate();

  }

  @override
  Widget buildView(BuildContext context) {
    // TODO: implement buildView
    return Column(
      children: <Widget>[
        RaisedButton(onPressed: (){
          addOverlay();
        },child: Text('添加overLay'),),

        RaisedButton(onPressed: (){
          removeOverlay();
        },child: Text('移除overLay'),),

        RaisedButton(onPressed: (){
          isAdded();
        },child: Text('是否添加'),),
      ],
    );
  }

  removeOverlay(){
    overlayEntry?.remove();
    overlayState = null;
    overlayEntry = null;
  }

  OverlayEntry overlayEntry;
  OverlayState overlayState;
  addOverlay(){

    if(overlayState?.debugIsVisible(overlayEntry) ?? false){
      showToast('已经添加过了');
    }else{
      overlayState = Overlay.of(context);
      overlayEntry = OverlayEntry(builder:(BuildContext context) => Positioned(child:Icon(Icons.check_circle),));
      overlayState.insert(overlayEntry);
    }

  }

  isAdded(){
    if(overlayState.debugIsVisible(overlayEntry)){
      showToast('已经添加过了');
    }else{
      showToast('没有添加过');
    }
  }

  @override
  void onDestroy() {
    // TODO: implement onDestroy
    removeOverlay();
    super.onDestroy();
  }


  @override
  PreferredSizeWidget initAppbar() {
    // TODO: implement initAppbar
    return AppBarCreator.create(context, 'overlay');
  }
}